<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 需要加入区域模块
 */
class MeterInfoAction extends CommonAction {  
    function _filter(&$map){
		if ($_POST['name']=='请输入关键字')$_POST['name']='';
		$map['name'] = array('like',"%".$_POST['name']."%");
    }
    
    public function index()
    {
        //读取系统的用户列表
      //读取系统的用户列表
        $tmp_date=date("Ym");
        $tmp_mon =substr($tmp_date,4,2);
        $tmp_year =substr($tmp_date,0,4);
        //读取更新信息
        $zone   =   D("Zone");
        $list=$zone->alias
('zone')->join(C('DB_PREFIX').'record_statistics record ON zone.id=record.zoneid AND record.mondate='.$tmp_date)
->where('zone.pid=1')->field('zone.id,name,biznum,zoneid,mondate,inputNum,paynum,Unfinished,invoNum')->select();

        
        
         for($i=0;$i<intval($tmp_mon);$i++){
           
            $listMon[$i]['id']=$tmp_year. str_pad($i+1,2,'0', STR_PAD_LEFT);
            $listMon[$i]['name']=$tmp_year.'年'.str_pad($i+1,2,'0', STR_PAD_LEFT).'月';
        }
        $this->assign('listMon',$listMon);
        $this->assign('mon',$tmp_mon);
        $this->assign('year',$tmp_year);
        $this->assign('list',$list);
        
        $this->display();

        return;
    }
    public function  comList()
    {
       $pId =  isset($_GET['zoneid'])?$_GET['zoneid']:1;
       $monid =  isset($_GET['monid'])?$_GET['monid']:1;
       $tmp_year =  isset($_GET['year'])?$_GET['year']:substr(date("Ym"),0,4);
       $tmp_mon =  isset($_GET['mon'])?$_GET['mon']:substr(date("Ym"),4,2);
        $zones = F('zones');


       
       
        //读取系统的用户列表
        $zone    =   M("Zone");
        $zonename = $zone->where('id='.$pId)->getField('name');
        $company    =   D("BizrecordView");
       /*$list=$company->alias
('biz')->join(C('DB_PREFIX').'meter_record record ON biz.id=record.bizid AND record.meterMon='.$tmp_year.$tmp_mon)
->field('biz.id, biz.name,biz.tel,biz.contact,biz.zoneid,biz.typeid,biz.meternum1,biz.meternum2,biz.bizSid,'.
        'biz.lastdate,record.id AS meterid,record.meterMon,record.wnum1,record.enum1,record.inputflag')->select();

*/
       if($monid==1){
           $monid =date("Ym");
       }
        if($pId!=1){
           $where['zoneid']=$pId ;
       }
        if($monid!=1){
           $where['meterMon']=$monid ;
       }
        $where['status']=1;
        //$where['mon']=$tmp_mon;
        //$where['year']=$tmp_year;

       if (!empty($company)) {
            $this->_list($company, $where,'id',true);
        }
       for($i=0;$i<intval($tmp_mon);$i++){
           
            $listMon[$i]['id']=$tmp_year. str_pad($i+1,2,'0', STR_PAD_LEFT);
            $listMon[$i]['name']=$tmp_year.'年'.str_pad($i+1,2,'0', STR_PAD_LEFT).'月';
        }
        $this->assign('listMon',$listMon);
       $this->assign('mon',$tmp_mon);
       $this->assign('monid',$monid);
       $this->assign('year',$tmp_year);
        $this->assign('zoneid',$pId);
        $this->assign('zones',$zones);
       $this->assign('zonename',$zonename); 
       //$this->assign('list',$list);
        Cookie::set('_currentUrl_', __SELF__);
        $this->display();

        return;
    }
    public function addMeterItem()
    {
        $model = D("BizManageView");
        $id = $_REQUEST [$model->getPk()];
        $tmp_date=date("Ym");
        $tmp_mon =substr($tmp_date,4,2);

        $com = $model->getById($id);
        foreach ($list as $com){
			$comList[$vo['id']]	=	$com['name'];
		}

        $meters = D("MeterInfo"); 
        $list=$meters->where('bizid ='.$id)->select();
        
        for($i=0;$i<sizeof($list);$i++)
                {
                    if ($list[$i]['metertype']== 1){
                        $w_meterlist[]=$list[$i];
                    }else{
                        $e_meterlist[]=$list[$i];
                    }
                }
         $this->assign('listw',$w_meterlist);
         $this->assign('liste',$e_meterlist);
        
        
        $this->assign('com',$com);
        $this->assign('now_mon',$tmp_mon);
        $this->display();
        return;
    }
        public function editMeterItem()
    {
        
         $sId =  isset($_GET['id'])?$_GET['id']:0;
          $Rd    =   D("MeterRecord");
          $where['id']= $sId;

          $record= $Rd->where($where)->find();
        $Biz=D("Bizmanage");
        $com=$Biz->where('id='.$record['bizid'])->find();
        $mitem= D("MeteritemView");
        $rsitems=$mitem->field('id,meterid,meterNum1,meterNum2,meterprice,metertype')->where('recordid='. $sId )->select(); 
        
        $tmp_date=$mon;
        $tmp_mon =substr($tmp_date,4,2);

        
        for($i=0;$i<sizeof($rsitems);$i++)
                {
                   $rsitems[$i]['acount']= round(($rsitems[$i]['meterNum2']- $rsitems[$i]['meterNum1'])* $rsitems[$i]['meterprice'],2);
            if ($rsitems[$i]['metertype']== 1){
                        $w_meterlist[]=$rsitems[$i];
                    }else{
                        $e_meterlist[]=$rsitems[$i];
                    }
                }
         $this->assign('listw',$w_meterlist);
         $this->assign('liste',$e_meterlist);
         $this->assign('sid',$sId );
        
         $this->assign('record',$record);
        $this->assign('com',$com);
        $this->assign('now_mon',$tmp_mon);
        $this->display();
        return;
    }
    public function insert(){
          
          $mon= $_POST['thedate'];
          $bizid= $_POST['bizid'];
          $wid= $_POST['wids'];
          $eid= $_POST['eids'];
          $sid=  $_POST['bizSid'];
          $zoneid= $_POST['zoneid'];
          $ww_price=$_POST['ww_price'];
          //水表数据
          $wnum= (int)$_POST['wNum'];
          $wmeterNum1=$_POST['wmeterNum1'];
          $wmeterNum2=$_POST['wmeterNum2'];
          $wmeterprice=$_POST['wmeterprice'];
          $wNumCount=$_POST['wNumCount'];
          //电表数据
          $enum= (int)$_POST['eNum'];
          $emeterNum1=$_POST['emeterNum1'];
          $emeterNum2=$_POST['emeterNum2'];
          $emeterprice=$_POST['emeterprice'];
          $eNumCount=$_POST['eNumCount'];

          
          $temp_w_data=0;
            $temp_w=0;
             $temp_e=0;

          $temp_e_data=0;
        //水表数据累加
          for($i=0;$i<$wnum;$i++){
              if ($wmeterNum1[$i]>=$wmeterNum2[$i]){
                    $temp_w_data= $temp_w_data+(($wmeterNum1[$i]-$wmeterNum2[$i])*$wmeterprice[$i]);
                    $temp_w=$temp_w+($wmeterNum1[$i]-$wmeterNum2[$i]);
              }else{
                if (($wmeterNum1[$i]<$wmeterNum2[$i])&&($wmeterNum1[$i]!=0)){    
                  $this->error("输入错误，本月水表数据异常！");
                } 
              }
             
                
          }
          $data['wnum1']=$temp_w_data;
          $data['awnum']=$temp_w;
          $data['wwnum']= $temp_w *$ww_price;
          //电表数据累加 
          for($i=0;$i<$enum;$i++){
                 if ($emeterNum1[$i]>=$emeterNum2[$i]){
                   $temp_e_data= $temp_e_data+ round((($emeterNum1[$i]-$emeterNum2[$i])*$emeterprice[$i]),2);
                   $temp_e=$temp_e+($emeterNum1[$i]-$emeterNum2[$i]);
               }else{
                 if (($emeterNum1[$i]<$emeterNum2[$i])&&($emeterNum1[$i]!=0)){    
                   $this->error("输入错误，本月电表数据异常！");
                 }  
               }
           }
         $data['enum1']=$temp_e_data;  //电总金额
         $data['aenum']=$temp_e;  //电总计量
         $data['bizid']=$bizid;
         $data['meterMon']=$mon;
         $data['userid']=$_SESSION[C('USER_AUTH_KEY')];
         $data['inputflag']=1; //输入完成标记
         $data['inputdate']=Time(now);
         $mon=str_replace('-','',$mon);
         
         $data['resid']=substr($mon,2,4).$sid;
         $year=substr($mon,0,4);
         $MeterRecord= D("MeterRecord");  
            //启用事务
         if($data['wnum1']>=0 &&  $data['enum1']>=0  ){
                $untype=1;
            if($temp_w>0&&$temp_e>0){
                $untype=0;
            }
         $MeterRecord->startTrans();
         
         if (false === $MeterRecord->create()) {
            $this->error($MeterRecord->getError());
           }else{
               //如果水电表的总金额都为0，本月水电表数据无需支付。支付标记标记为-1
               if($data['wnum1']==0 &&  $data['enum1']==0  ){
                        $data['payflag']=-1;
                }
                
               $result= $MeterRecord->add($data);
               //逐条插入表记录
               if($result ){
                        
                        //更新最后月份信息
                        $MeterRecord->updateLastMon($data['bizid'],$data['meterMon']);
                        //更新月统计信息
                        $MeterRecord->setCount($zoneid,$mon,$untype);
                        
                        //更新单位年月统计记录表

                        $MeterRecord->setMeterStatistics($data['bizid'],1,$year,substr($mon,4,2),$temp_w);  
                        $MeterRecord->setMeterStatistics($data['bizid'],2,$year,substr($mon,4,2),$temp_e); 
                        
                        //$MeterRecord->setMeterStatisticsCache($year);
                        //水表数据
                        $wresult=True;
                        for($i=0;$i<$wnum;$i++){
                            $wdata['meterid']=$wid[$i];
                            $wdata['bizid']=$bizid;
                            $wdata['meterNum1']=$wmeterNum2[$i];//上月表数
                            $wdata['meterNum2']=$wmeterNum1[$i];//本月表数
                            $wdata['meterprice']=$wmeterprice[$i];
                            
                            $wdata['recordid']=$result;
                            $wdata['last_update']=$data['meterMon'];
                           if(is_numeric($wdata['meterNum2'])){
                                    if($wmeterNum1[$i]<$wmeterNum2[$i]){
                                        $wdata['meterNum1']=$wmeterNum2[$i];//上月表数
                                        $wdata['meterNum2']=$wmeterNum2[$i];//上月表数
                             
                                    }

                                        $wresult= $MeterRecord->addMeterItem($wdata);
                           }

           
                        }
                        //电表数据
                        $eresult=True;
                        for($i=0;$i<$enum;$i++){
                 
                            $edata['meterid']=$eid[$i];
                            $edata['bizid']=$bizid;
                            $edata['meterNum1']=$emeterNum2[$i];//上月表数
                            $edata['meterNum2']=$emeterNum1[$i];//本月表数
                            $edata['meterprice']=$emeterprice[$i];
                            $edata['recordid']=$result;
                            $edata['last_update']=$data['meterMon'];
                            if(is_numeric($edata['meterNum2'])){
                                    if($emeterNum1[$i]<$emeterNum2[$i]){
                                          $edata['meterNum1']=$emeterNum2[$i];//上月表数
                                        $edata['meterNum2']=$emeterNum2[$i];//上月表数
                                    }
                                     $eresult=$MeterRecord->addMeterItem($edata);
                                       
                           }
                           
                        }
                }
           }
           
           if($result&&($wresult&&$eresult)){
               
               
               $MeterRecord->commit();//成功则体积哦啊
               //$this->assign('jumpUrl', Cookie::get('_currentUrl_'));
              //$this->success('添加新商户成功！');
                $ajaxdata['jumpUrl']=Cookie::get('_currentUrl_');
                $ajaxdata['printtype']=0;
                $ajaxdata['id']=$result;
                 $this->ajaxReturn($ajaxdata,"添加数据成功！",1);
				
               
               
            }else{
                $MeterRecord->rollback();//不成功，回滚
                 $this->ajaxReturn(0,"添加数据失败！",0);
            }
         }
        //保存当前数据对象

        return;
        
    }
 public function updateInfo(){
          
          $mon= $_POST['thedate'];
          $data['id']= $_POST['id'];
          $bizid= $_POST['bizid'];
          $wid= $_POST['wids'];
          $eid= $_POST['eids'];
          $sid=  $_POST['bizSid'];
          $zoneid= $_POST['zoneid'];
          $ww_price=$_POST['ww_price'];
          //水表数据
          $wnum= (int)$_POST['wNum'];
          $wmeterNum1=$_POST['wmeterNum1'];
          $wmeterNum2=$_POST['wmeterNum2'];
          $wmeterprice=$_POST['wmeterprice'];
          $wNumCount=$_POST['wNumCount'];
          //电表数据
          $enum= (int)$_POST['eNum'];
          $emeterNum1=$_POST['emeterNum1'];
          $emeterNum2=$_POST['emeterNum2'];
          $emeterprice=$_POST['emeterprice'];
          $eNumCount=$_POST['eNumCount'];

          
          $temp_w_data=0;
            $temp_w=0;
             $temp_e=0;

          $temp_e_data=0;
        //水表数据累加
          for($i=0;$i<$wnum;$i++){
              if ($wmeterNum1[$i]>=$wmeterNum2[$i]){
                    $temp_w_data= $temp_w_data+(($wmeterNum1[$i]-$wmeterNum2[$i])*$wmeterprice[$i]);
                    $temp_w=$temp_w+($wmeterNum1[$i]-$wmeterNum2[$i]);
              }else{
                if (($wmeterNum1[$i]<$wmeterNum2[$i])&&($wmeterNum1[$i]!=0)){    
                  $this->error("输入错误，本月水表数据异常！");
                } 
              }
             
                
          }
          $data['wnum1']=$temp_w_data;
          $data['awnum']=$temp_w;
          $data['wwnum']= $temp_w *$ww_price;
          //电表数据累加 
          for($i=0;$i<$enum;$i++){
                 if ($emeterNum1[$i]>=$emeterNum2[$i]){
                   $temp_e_data= $temp_e_data+ round((($emeterNum1[$i]-$emeterNum2[$i])*$emeterprice[$i]),2);
                   $temp_e=$temp_e+($emeterNum1[$i]-$emeterNum2[$i]);
               }else{
                 if (($emeterNum1[$i]<$emeterNum2[$i])&&($emeterNum1[$i]!=0)){    
                   $this->error("输入错误，本月电表数据异常！");
                 }  
               }
           }
         $data['enum1']=$temp_e_data;  //电总金额
         $data['aenum']=$temp_e;  //电总计量
         $data['bizid']=$bizid;
        
         $data['userid']=$_SESSION[C('USER_AUTH_KEY')];
         $data['inputflag']=1; //输入完成标记
         $data['inputdate']=Time(now);
         $mon=str_replace('-','',$mon);
          $data['meterMon']=substr($mon,0,6);
         $data['resid']=substr($mon,2,4).$sid;
         $year=substr($mon,0,4);
         $MeterRecord= D("MeterRecord");  
            //启用事务
         if($data['wnum1']>=0 &&  $data['enum1']>=0  ){
                $untype=1;
            if($temp_w>0&&$temp_e>0){
                $untype=0;
            }
         $MeterRecord->startTrans();
         
         if (false == $MeterRecord->create()) {
            $this->error($MeterRecord->getError());
           }else{
               //如果水电表的总金额都为0，本月水电表数据无需支付。支付标记标记为-1
               if($data['wnum1']==0 &&  $data['enum1']==0  ){
                        $data['payflag']=-1;
                }
                
               $result= $MeterRecord->save($data);
               //逐条插入表记录
               if($result ){
                        
                       
                        //更新单位年月统计记录表

                        $MeterRecord->setMeterStatistics($data['bizid'],1,$year,substr($mon,4,2),$temp_w);  
                        $MeterRecord->setMeterStatistics($data['bizid'],2,$year,substr($mon,4,2),$temp_e); 
                        
                        
                        //水表数据
                        $wresult=True;
                        for($i=0;$i<$wnum;$i++){
                            $wdata['meterid']=$wid[$i];
                            $wdata['bizid']=$bizid;
                            $wdata['meterNum1']=$wmeterNum2[$i];//上月表数
                            $wdata['meterNum2']=$wmeterNum1[$i];//本月表数
                            $wdata['meterprice']=$wmeterprice[$i];
                            
                            $wdata['recordid']=$result;
                            $wdata['last_update']=$data['meterMon'];
                           if(is_numeric($wdata['meterNum2'])){
                                    if($wmeterNum1[$i]<$wmeterNum2[$i]){
                                        $wdata['meterNum1']=$wmeterNum2[$i];//上月表数
                                        $wdata['meterNum2']=$wmeterNum2[$i];//上月表数
                             
                                    }

                                        $wresult= $MeterRecord->updateMeterItem($wdata);
                           }

           
                        }
                        //电表数据
                        $eresult=True;
                        for($i=0;$i<$enum;$i++){
                 
                            $edata['meterid']=$eid[$i];
                            $edata['bizid']=$bizid;
                            $edata['meterNum1']=$emeterNum2[$i];//上月表数
                            $edata['meterNum2']=$emeterNum1[$i];//本月表数
                            $edata['meterprice']=$emeterprice[$i];
                            $edata['recordid']=$result;
                            $edata['last_update']=$data['meterMon'];
                            if(is_numeric($edata['meterNum2'])){
                                    if($emeterNum1[$i]<$emeterNum2[$i]){
                                          $edata['meterNum1']=$emeterNum2[$i];//上月表数
                                        $edata['meterNum2']=$emeterNum2[$i];//上月表数
                                    }
                                     $eresult=$MeterRecord->updateMeterItem($edata);
                                       
                           }
                           
                        }
                }
           }
           
           if($result&&($wresult&&$eresult)){
               
               
               $MeterRecord->commit();//成功则体积哦啊
               //$this->assign('jumpUrl', Cookie::get('_currentUrl_'));
              //$this->success('添加新商户成功！');
                $ajaxdata['jumpUrl']=Cookie::get('_currentUrl_');
                $ajaxdata['printtype']=0;
                $ajaxdata['id']=$result;
                 $this->ajaxReturn($ajaxdata,"添加数据成功！",1);
				
               
               
            }else{
                $MeterRecord->rollback();//不成功，回滚
                 $this->ajaxReturn(0,"添加数据失败！",0);
            }
         }
        //保存当前数据对象

        return;
        
    }
    public function meterrecordList()
    {
       $pId =  isset($_GET['pid'])?$_GET['pid']:1;
        //读取系统的用户列表
        $zone    =   M("Zone");
	$zonename = $zone->where('id='.$pId)->getField('name');
       $company    =   D("MeterrecordView");
       $list=$company->where('status=1 AND (water=1 OR electricity=1) AND zoneid ='.$pId)->select();
            
		//dump(	$user);
		// 设计服务开通标识
       $this->assign('zonename',$zonename); 
       $this->assign('list',$list);
        
        $this->display();

        return;
    }
    //打印通知单
    public function printPost(){
         $sId =  isset($_GET['id'])?$_GET['id']:0;
          $mon =  isset($_GET['monid'])?$_GET['monid']:0;
          
                //保存打印记录，更新打印次数
           import ( '@.ORG.Util.ChineseUnicode' );
           $Rd    =   D("BizrecordView");
           $where['id']= $sId;
           $where['meterMon']= $mon;
           $record= $Rd->where($where)->find();
                    //查询RecordItem
           $mitem= D("MeteritemView");
           $rsitems=$mitem->field('meterid,meterNum1,meterNum2,meterprice,metertype')->where('recordid='. $record['meterid'] )->select(); 
             for($i=0;$i<sizeof($rsitems);$i++)
             {
                  
                 if ($rsitems[$i]['metertype']== 1){

                        $w_meterlist[$i][0]=$rsitems[$i]['meterid'];
                        $w_meterlist[$i][1]=$rsitems[$i]['meterNum1'];
                        $w_meterlist[$i][2]=$rsitems[$i]['meterNum2'];
                        $w_meterlist[$i][3]=$rsitems[$i]['meterNum2']- $rsitems[$i]['meterNum1'];
                         $w_meterlist[$i][4]=$rsitems[$i]['meterprice'];
                        $w_meterlist[$i][5]=  round(($rsitems[$i]['meterNum2']- $rsitems[$i]['meterNum1'])* $rsitems[$i]['meterprice'],2);
                    }else{
                        $e_meterlist[$i][0]=$rsitems[$i]['meterid'];
                        $e_meterlist[$i][1]=$rsitems[$i]['meterNum1'];
                        $e_meterlist[$i][2]=$rsitems[$i]['meterNum2'];
                        $e_meterlist[$i][3]=$rsitems[$i]['meterNum2']- $rsitems[$i]['meterNum1'];
                         $e_meterlist[$i][4]=$rsitems[$i]['meterprice'];
                        $e_meterlist[$i][5]=  round(($rsitems[$i]['meterNum2']- $rsitems[$i]['meterNum1'])* $rsitems[$i]['meterprice'],2);
                    } 
              }
           
           

           // 提取打印数据 合成打印报表 
                        $init=array(215.9,93.1);

                        $pdf=new PDF_Unicode('UTF-8','L','mm',$init); 
                        $pdf->Open(); 
                        $pdf->AddUniGBhwFont('simhei','黑体'); 
                        $pdf->AddUniGBhwFont('simsun','宋体'); 
                        //$pdf->SetFont('uni','',20); 

                        $pdf->Open(); 
                        $pdf->AddPage(); 


                        //$pdf->AddGBhwFont('simhei','黑体'); 
                        //$pdf->AddGBhwFont('simsun','宋体'); 
                        $pdf->SetMargins(5,8,5); 
                        $pdf->SetFont('simhei','','12'); 
                        $pdf->SetXY(7,5); 
                        $pdf->Text(78,9,'振兴市政水电费缴费通知单');
                        $pdf->SetFont('simhei','','10'); 
                        $pdf->Text(180,10,'2011年7月');
                        $pdf->Text(7,10,'单据号:'.$record['resid']);
                        $pdf->Line(7,11,210,11);

                        $pdf->Text(7,15,'名称:'.$record['name']);

                         $pdf->SetXY(7,17);
                          $pdf->SetFont('simsun','','10'); 
                        $header=array('表号','本月数','上月数','计量','单价','合计'); //设置表头


                        $width=array(34,33,33,34,34,34); //设置每列宽度
                        $pdf->Cell(202,6,'水电费明细',0);
                        $pdf->Ln();
                         $pdf->SetX(7);
                        for($i=0;$i<count($header);$i++) //循环输出表头
                        $pdf->Cell($width[$i],6,$header[$i],'TB');
                        $pdf->Ln();

                        foreach($e_meterlist as $row) //循环输出表体
                        {
                            $pdf->SetX(7);
                            $pdf->Cell($width[0],6,$row[0],0);
                            $pdf->Cell($width[1],6,$row[1],0);
                            $pdf->Cell($width[2],6,$row[2],0);
                            $pdf->Cell($width[3],6,$row[3],0);
                            $pdf->Cell($width[4],6,$row[4],0);
                            $pdf->Cell($width[4],6,$row[5],0);
                            $pdf->Ln();
                        }
                        foreach($w_meterlist as $row) //循环输出表体
                        {
                            $pdf->SetX(7);
                            $pdf->Cell($width[0],6,$row[0],0);
                            $pdf->Cell($width[1],6,$row[1],0);
                            $pdf->Cell($width[2],6,$row[2],0);
                            $pdf->Cell($width[3],6,$row[3],0);
                            $pdf->Cell($width[4],6,$row[4],0);
                            $pdf->Cell($width[4],6,$row[5],0);
                            $pdf->Ln();
                        }
                        $pdf->SetX(7);
                        $pdf->Cell($width[0],6,'污水处理费',0);
                        $pdf->Cell($width[1],6,'',0);
                        $pdf->Cell($width[2],6,'',0);
                        $pdf->Cell($width[3],6,$record['awnum'],0);
                        $pdf->Cell($width[4],6,$record['ww_price'],0);
                        $pdf->Cell($width[4],6,$record['wwnum'],0);  
                        $pdf->Line(7,78,210,78);
                         $pdf->Text(7,82,'合计金额：'.($record['wnum1']+$record['enum1']+$record['wwnum']));
                      
                        $pdf->IncludeJS("print({bUI: false,bSilent: true,bShrinkToFit: false});closeDoc();"); 
                        //$pdf->Output('foobar.pdf','I');
                        $pdf->Output(); //输出PDF 到浏览器
         
          
          
          
          //没有标识说明打印未成功，只打印，不更新记录了。
          //下面是打印处理了
    }
    function printcount(){
                 //如果标识为1说明一次成功
         $bizid =  isset($_GET['bid'])?$_GET['bid']:0;
         $meterid =  isset($_GET['meterid'])?$_GET['meterid']:0;
                   
                    //获得全部数据
                    $data['bizid']= intval($bizid);
                    $data['user_id']= intval($_SESSION[C('USER_AUTH_KEY')]);
                    $data['printtype']=0;
                    $data['printid']=  intval($meterid);
                    //$data['printdate']=time(Now);
                    $print = D("PrintRecord");
                    if (!$print->create( $data)) {
                         $this->error( $print->getError());
                    }else{
                         $result=  $print->add();
                                   
                            if ($result){
                                  $print->updatePrint($meterid);
                            }
                    }
                    //$this->display();
                    $this->ajaxReturn('计数成功',1,1);
    }
    
}
?>
